import { request } from "../../utils/request";
import config from "../../utils/config";
const app = getApp();
Page({
    data: {
        picUrl: config.picUrl,
        custom: wx.getMenuButtonBoundingClientRect(),
        list:[
            {title:'发布新剧',url:'/pages/add_new/add_new',color:"#ee833b"},
            // {title:'发布闲置',url:'/pages/add_juben_old/add_detail?type=1',color:"#ffc821"},
            {title:'发布闲置',url:'/pages/add_old_2/add_new',color:"#ffc821"},
            {title:'求购好剧',url:'/pages/beg_good/add_detail',color:"#76abdc"},
            {title:'发布周边',url:'/pages/add_old/add_old',color:"#78b151"},
            {title:'分享心得',url:'/pages/add_share/add_share',color:'#0d0d0d'}
        ],
        user:{}
    },
    onLoad(options) {
        var timer = setInterval(()=>{
            var user = wx.getStorageSync('userInfo')
            if(user){
                this.setData({user})
                if(user.authentication_type == 3){
                    this.setData({
                        list:[
                            {title:'发布新剧',url:'/pages/add_new/add_new',color:"#ee833b"},
                            {title:'分享心得',url:'/pages/add_share/add_share',color:'#0d0d0d'}
                        ]
                    })
                }else if(user.authentication_type == 4){
                    this.setData({
                        list:[
                            {title:'发布闲置',url:'/pages/add_old_2/add_new',color:"#ffc821"},
                            {title:'求购好剧',url:'/pages/beg_good/add_detail',color:"#76abdc"},
                            {title:'发布周边',url:'/pages/add_old/add_old',color:"#78b151"},
                            {title:'分享心得',url:'/pages/add_share/add_share',color:'#0d0d0d'}
                        ]
                    })
                }
                clearInterval(timer)
            }
        },500)
        
    },
    onShow(){
        if (typeof this.getTabBar === 'function' && this.getTabBar()) {
            this.getTabBar().setData({
                selected: 2
            })
        }
    },
    nav(e){
        var {url,index} = e.currentTarget.dataset
        var timeStamp = Date.now()
        var info =wx.getStorageSync('userInfo')
        if(info.is_wechat_authentication != 1){
            wx.showModal({
                title:'提示',
                content:"您还未登录或注册，请先登录",
                cancelText:"取消",
                confirmText:"登录",
                success:res=>{
                    if(res.confirm){
                        wx.switchTab({url:"/pages/my/my"})
                    }else{

                    }
                }
            })
            return false
        }
        if(info.authentication_type == 5){
            //没做任何认证，提示先去认证。
            wx.showModal({
                title:'提示',
                content:"您还未进行身份认证，请先认证您身份信息",
                cancelText:"认证商户",
                confirmColor:"#000",
                confirmText:"认证发行",
                success:res=>{
                    if(res.confirm){
                        wx.navigateTo({url:"/pages/publisher_auth/publisher_auth"})
                    }else{
                        wx.navigateTo({url:"/pages/merchant_auth/merchant_auth"})
                    }
                }
            })
        }else if(this.data.user.expire != 1){
            if(info.authentication_type == 3){
                //没做任何认证，提示先去认证。
                wx.showModal({
                    title:'提示',
                    content:"您还未进行进行会员充值，请先充值会员",
                    showCancel:false,
                    confirmText:"充值会员",
                    success:res=>{
                        if(res.confirm) {
                            wx.navigateTo({url: '/pages/member_recharge/member_recharge'})
                        }
                    }
                })

            }else if(info.authentication_type == 4){
                wx.showModal({
                    title:'提示',
                    content:"您还未进行进行会员充值，请先充值会员",
                    showCancel:false,
                    confirmText:"充值会员",
                    success:res=>{
                        if(res.confirm) {
                            wx.navigateTo({url: '/pages/member_recharge2/member_recharge'})
                        }
                    }
                })
            }
        }else{
            wx.navigateTo({url})
        }
        
    }
})